package com.niit.session23.bank1;

public class Bank {
	private Integer money = 10000;

	public /* synchronized */ void getMoney(String name) {
		while (true) {
//			同步语句块，如果有多个线程来访问，会锁定资源
			synchronized (this) {
				if (money > 0) {
					money -= 1000;
					System.out.println(name + "取走了" + money);
				} else {
					System.out.println("取完了");
					break;
				}
				
			}
		}
	}
}
